const path = require('path')

function join(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  // 显式转译
  transpileDependencies: ['e-screen', 'element-ui'],

  // 资源根路径
  publicPath: process.env.VUE_APP_PUBLICPATH,

  // 打包根路径
  outputDir: 'screen-admin',

  // 静态资源文件夹
  assetsDir: 'static',

  // 保存时eslint校验
  lintOnSave: process.env.NODE_ENV === 'development' ? 'error' : true,

  // 生产环境 source-map
  productionSourceMap: false,

  // 调整webpack配置
  chainWebpack: config => {
    config.plugins.delete('prefetch')
    config.resolve.alias
      .set('api', join('src/api'))
      .set('assets', join('src/assets'))
      .set('components', join('src/components'))
      .set('filters', join('src/filters'))
      .set('router', join('src/router'))
      .set('store', join('src/store'))
      .set('style', join('src/style'))
      .set('utils', join('src/utils'))
      .set('views', join('src/views'))
    config.resolve.symlinks(true)
  },

  // 调整webpack的配置
  configureWebpack: config => {
    config.devtool = process.env.NODE_ENV === 'production' ? 'none' : 'cheap-eval-source-map'

    config.externals = {
      echarts: 'echarts'
    }
  },

  // css相关
  css: {
    // 是否开启 css source map
    sourceMap: false,

    // 预处理器的loader传递自定义选项
    loaderOptions: {}
  },

  // 开发环境 dev-server
  devServer: {
    open: false,
    host: '0.0.0.0',
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://118.190.232.100:8880/smart-bus/api/',
        pathRewrite: {
          '^/api': ''
        },
        logLevel: 'debug',
        changeOrigin: true,
        secure: false
      }
    },
    https: false,
    hotOnly: true
  }
}
